package com.maiji.cloud.controller.login;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.entities.login.Label;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.login.*;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseMetaResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.Status;
import com.maiji.cloud.response.login.RecipeResData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

@RestController
@RequestMapping("/recipe/")
@Api(tags = { "食谱模块" })
public class RecipeController extends BaseController {

	/**
	 * 根据标签查询食谱列表
	 * @param baseDataReqDto
	 * @return
	 */
	@ApiOperation(value = "根据标签获取食谱列表")
	@PostMapping("findAllRecipes")
	public BaseMetaResDto<List<RecipeResData>> findAllRecipes(@RequestBody BaseDataReqDto<RecipeFindAllReqData> baseDataReqDto) {
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/recipe/findAllRecipes", baseDataReqDto, BaseMetaResDto.class);
	}

    /**
     * 获取美食推荐食谱列表_PC
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "获取美食推荐食谱列表_PC")
    @PostMapping("findAllRecommendRecipes")
    public BaseMetaResDto<List<RecipeResData>> findAllRecommendRecipes(@RequestBody BaseDataReqDto baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/recipe/findAllRecommendRecipes", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     * 根据食谱ID获取食谱详情
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "根据食谱ID获取食谱详情")
    @PostMapping("findRecipeById")
    public BaseDataResDto<RecipeResData> findRecipeById(@RequestBody BaseDataReqDto<String> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/recipe/findRecipeById", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 根据食谱ID获取食谱的标签
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "根据食谱ID获取食谱的标签")
    @PostMapping("/findAllLabelsByRecipeId")
    public BaseDataResDto<List<Label>> findAllLabelsByRecipeId(@RequestBody BaseDataReqDto<String> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/recipe/findAllLabelsByRecipeId", baseDataReqDto, BaseDataResDto.class);
    }

	/**
	 * 逻辑删除食谱
	 * @param baseDataReqDto
	 * @return
	 */
	@ApiOperation(value = "逻辑删除食谱")
	@PostMapping("delRecipesByIds")
	public BaseResDto delRecipesByIds(@RequestBody BaseDataReqDto<List<String>> baseDataReqDto) {
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/recipe/delRecipesByIds", baseDataReqDto, BaseResDto.class);
	}

	/**
	 * 添加食谱
	 * @param baseDataReqDto
	 * @return
	 */
	@ApiOperation(value = "添加食谱")
	@PostMapping("addRecipe")
	public BaseResDto addRecipe(@RequestBody BaseDataReqDto<RecipeReqData> baseDataReqDto) {
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/recipe/addRecipe", baseDataReqDto, BaseResDto.class);
	}

	/**
	 * 编辑食谱
	 * @param baseDataReqDto
	 * @return
	 */
	@ApiOperation(value = "编辑食谱")
	@PostMapping("editRecipe")
	public BaseResDto editRecipe(@RequestBody BaseDataReqDto<RecipeReqData> baseDataReqDto) {
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/recipe/editRecipe", baseDataReqDto, BaseResDto.class);
	}

    /**
     *  批量导入食谱
     * @param uploadFile
     * @return
     */
    @PostMapping("uploadRecipes")
    @ApiOperation(value = "批量导入食谱")
    public BaseDataResDto<String> uploadRecipes(@RequestBody MultipartFile uploadFile) {
        try {
            return postForObjectWithMultipart(uploadFile, REST_URL_APPLOGIN + "/recipe/uploadRecipes", BaseDataResDto.class);
        } catch (Exception e) {
            e.printStackTrace();
            return new BaseDataResDto(Status.ERROR);
        }
    }

    /**
     * 添加或取消推荐
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "添加或取消推荐")
    @PostMapping("addOrCancelRecommend")
    public BaseResDto addOrCancelRecommend(@RequestBody BaseDataReqDto<String> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/recipe/addOrCancelRecommend", baseDataReqDto, BaseResDto.class);
    }

}
